package 力扣91;

/**
 * @ClassName : Day13_104_二叉树的最大深度
 * @Author : 骆发茂
 * @Date: 2021/12/24 22:36
 * @Description : https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/
 */
public class Day13_104_二叉树的最大深度_递归 {
    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     *     int val;
     *     TreeNode left;
     *     TreeNode right;
     *     TreeNode() {}
     *     TreeNode(int val) { this.val = val; }
     *     TreeNode(int val, TreeNode left, TreeNode right) {
     *         this.val = val;
     *         this.left = left;
     *         this.right = right;
     *     }
     * }
     */
    class Solution {
        public int maxDepth(TreeNode root) {
            if(root ==null){
                return 0;
            }
            if(root.left ==null &&root.right==null){
                return 1;
            }

            int m1 = maxDepth(root.left);
            int m2  = maxDepth(root.right);
            if(root.left ==null ||root.right==null){
                return m1+m2+1;
            }

            return Math.max(m1,m2)+1;
        }
    }
}